home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / sys / mac / mttymain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  14.2 KB  |  715 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)mttymain.c    3.1    93/02/26            */
  2. /* Copyright (c) Jon W{tte, 1993                    */
  3. /* NetHack may be freely redistributed.  See license for details.    */
  4.  
  5. #include "hack.h"
  6. #include "wintty.h"
  7. #include "mactty.h"
  8.  
  9. #include <stdarg.h>
  10. #include <Menus.h>
  11.  
  12. extern void InitRes ( void ) ;
  13. extern Boolean small_screen ;
  14. extern void DoMenu ( long ) ;
  15. extern void UpdateMenus ( void ) ;
  16. extern int GetFromKeyQueue ( void ) ;
  17. extern void dprintf ( char * , ... ) ;
  18.  
  19.  
  20. #define POWER_LIMIT 22
  21. #define SECONDARY_POWER_LIMIT 16
  22. #define CHANNEL_LIMIT 14
  23. #define SECONDARY_CHANNEL_LIMIT 12
  24.  
  25. #define MT_WINDOW 135
  26. #define MT_WIDTH 80
  27. static short MT_HEIGHT = 24;
  28.  
  29.  
  30. /*
  31.  * Names:
  32.  *
  33.  * Statics are prefixed _
  34.  * Mac-tty becomes mt_
  35.  */
  36.  
  37.  
  38. static void _mt_set_colors ( long * colors ) ;
  39.  
  40.  
  41. static long _mt_attrs [ 5 ] [ 2 ] = {
  42.     { 0x202020 , 0xffffff } , /* Normal */
  43.     { 0xff8080 , 0xffffff } , /* Underline */
  44.     { 0x40c020 , 0xe0e0e0 } , /* Bold */
  45.     { 0x003030 , 0xff0060 } , /* Blink */
  46.     { 0xff8888 , 0x000000 } , /* Inverse */
  47. } ;
  48.  
  49.  
  50. static char _attrs_inverse [ 5 ] = {
  51.     0 , 0 , 0 , 0 , 0 ,
  52. } ;
  53.  
  54.  
  55. #if 0
  56. #define BLACK        0
  57. #define RED        1
  58. #define GREEN        2
  59. #define BROWN        3    /* on IBM, low-intensity yellow is brown */
  60. #define BLUE        4
  61. #define MAGENTA     5
  62. #define CYAN        6
  63. #define GRAY        7    /* low-intensity white */
  64. #define NO_COLOR    8
  65. #define ORANGE_COLORED    9    /* "orange" conflicts with the object */
  66. #define BRIGHT_GREEN    10
  67. #define YELLOW        11
  68. #define BRIGHT_BLUE    12
  69. #define BRIGHT_MAGENTA  13
  70. #define BRIGHT_CYAN    14
  71. #define WHITE        15
  72. #define MAXCOLORS    16
  73. #endif
  74.  
  75. static long _mt_colors [ 16 ] [ 2 ] = {
  76.     { 0x000000 , 0xaaaaaa } , /* Black */
  77.     { 0x880000 , 0xffffff } , /* Red */
  78.     { 0x008800 , 0xffffff } , /* Green */
  79.     { 0x553300 , 0xffffff } , /* Brown */
  80.     { 0x000088 , 0xffffff } , /* Blue */
  81.     { 0x770077 , 0xffffff } , /* Magenta */
  82.     { 0x007777 , 0xffffff } , /* Cyan */
  83.     { 0x888888 , 0xffffff } , /* Gray */
  84.     { 0x222222 , 0xffffff } , /* No Color */
  85.     { 0xeeee00 , 0x606060 } , /* Orange */
  86.     { 0x00ff00 , 0x606060 } , /* Bright Green */
  87.     { 0xeeee00 , 0x606060 } , /* Yellow */
  88.     { 0x0000ff , 0x606060 } , /* Bright Blue */
  89.     { 0xee00ee , 0x606060 } , /* Bright Magenta */
  90.     { 0x00eeee , 0x606060 } , /* Bright Cyan */
  91.     { 0x000000 , 0xffffff } , /* White */
  92. } ;
  93.  
  94. static char _colors_inverse [ MAXCOLORS ] = {
  95.     1 , 0 , 0 , 0 ,
  96.     0 , 0 , 0 , 0 ,
  97.     0 , 0 , 0 , 0 ,
  98.     0 , 0 , 0 , 0 ,
  99. } ;
  100.  
  101.  
  102. #ifdef CHANGE_COLOR
  103.  
  104. void
  105. tty_change_color ( int color , long rgb , int reverse ) {
  106. long inverse = 0 , the_rgb = rgb ;
  107. int total_power = 0 , max_channel = 0 ;
  108. int cnt = 3 ;
  109.  
  110.     the_rgb >>= 4 ;
  111.     while ( cnt -- > 0 ) {
  112.         total_power += the_rgb & 0xf ;
  113.         max_channel = max ( max_channel , the_rgb & 0xf ) ;
  114.         the_rgb >>= 8 ;
  115.     }
  116.  
  117.     if ( total_power >= POWER_LIMIT ||
  118.         ( total_power >= SECONDARY_POWER_LIMIT &&
  119.             max_channel >= SECONDARY_CHANNEL_LIMIT ) ||
  120.         max_channel >= CHANNEL_LIMIT ) {
  121.         inverse = 0x000000 ;
  122.     } else {
  123.         inverse = 0xffffff ;
  124.     }
  125.  
  126.     if ( reverse ) {
  127.     long rev = rgb ;
  128.  
  129.         rgb = inverse ;
  130.         inverse = rev ;
  131.     }
  132.  
  133.     if ( color >= MAXCOLORS ) {
  134.         if ( color - MAXCOLORS >= 5 ) {
  135.             impossible ( "Changing too many colors" ) ;
  136.             return ;
  137.         }
  138.         _mt_attrs [ color - MAXCOLORS ] [ 0 ] = rgb ;
  139.         _mt_attrs [ color - MAXCOLORS ] [ 1 ] = inverse ;
  140.         _attrs_inverse [ color - MAXCOLORS ] = reverse ;
  141.     } else if ( color >= 0 ) {
  142.         _mt_colors [ color ] [ 0 ] = rgb ;
  143.         _mt_colors [ color ] [ 1 ] = inverse ;
  144.         _colors_inverse [ color ] = reverse ;
  145.     } else {
  146.         impossible ( "Changing negative color" ) ;
  147.     }
  148. }
  149.  
  150.  
  151. static char color_buf [ 5 * ( MAXCOLORS + 5 ) + 1 ] ;
  152.  
  153. char *
  154. tty_get_color_string ( void ) {
  155. char tmp [ 10 ] ;
  156. int count ;
  157.  
  158.     color_buf [ 0 ] = 0 ;
  159.  
  160.     for ( count = 0 ; count < MAXCOLORS ; count ++ ) {
  161.     int flag = _colors_inverse [ count ] ? 1 : 0 ;
  162.  
  163.         sprintf ( tmp , "%s%s%x%x%x" , count ? "/" : "" ,
  164.             flag ? "-" : "" ,
  165.             ( _mt_colors [ count ] [ flag ] >> 20 ) & 0xf ,
  166.             ( _mt_colors [ count ] [ flag ] >> 12 ) & 0xf ,
  167.             ( _mt_colors [ count ] [ flag ] >> 4 ) & 0xf ) ;
  168.         strcat ( color_buf , tmp ) ;
  169.     }
  170.     for ( count = 0 ; count < 5 ; count ++ ) {
  171.     int flag = _colors_inverse [ count ] ? 1 : 0 ;
  172.  
  173.         sprintf ( tmp , "/%s%x%x%x" ,
  174.             flag ? "-" : "" ,
  175.             ( _mt_attrs [ count ] [ flag ] >> 20 ) & 0xf ,
  176.             ( _mt_attrs [ count ] [ flag ] >> 12 ) & 0xf ,
  177.             ( _mt_attrs [ count ] [ flag ] >> 4 ) & 0xf ) ;
  178.         strcat ( color_buf , tmp ) ;
  179.     }
  180.  
  181.     return color_buf ;
  182. }
  183. #endif
  184.  
  185.  
  186. extern struct DisplayDesc *ttyDisplay;    /* the tty display descriptor */
  187.  
  188. char kill_char = 27 ;
  189. char erase_char = 8 ;
  190.  
  191. WindowPtr _mt_window = (WindowPtr) NULL ;
  192. static Boolean _mt_in_color = 0 ;
  193.  
  194.  
  195. static void
  196. _mt_init_stuff ( void )
  197. {
  198. long resp , flag ;
  199. short num_cols , num_rows , win_width , win_height , font_num , font_size ;
  200. short char_width , row_height ;
  201. short hor , vert ;
  202.  
  203. #if 1
  204.     if ( !strcmp(windowprocs.name, mac_procs.name) ) {
  205.         dprintf ( "Mac Windows" ) ;
  206.         MT_HEIGHT -= 1 ;
  207.     } else {
  208.         dprintf ( "TTY Windows" ) ;
  209.     }
  210. #else
  211.     if (!strcmp(windowprocs.name, "mac")) {
  212.         MT_HEIGHT -= 1;    /* the message box is in a separate window */
  213.     }
  214. #endif
  215.  
  216.     LI = MT_HEIGHT ;
  217.     CO = MT_WIDTH ;
  218.  
  219.     /*
  220.      * If there is at least one screen CAPABLE of color, and if
  221.      * 32-bit QD is there, we use color. 32-bit QD is needed for the
  222.      * offscreen GWorld
  223.      */
  224.     if ( ! Gestalt ( gestaltQuickdrawVersion , & resp ) && resp > 0x1ff ) {
  225.     GDHandle gdh ;
  226.  
  227.         gdh = GetDeviceList ( ) ;
  228.         while ( gdh ) {
  229.             if ( TestDeviceAttribute ( gdh , screenDevice ) ) {
  230.                 if ( HasDepth ( gdh , 8 , 1 , 1 ) ||
  231.                     HasDepth ( gdh , 12 , 1 , 1 ) || /* Intuition tells me this may happen
  232.                                                         on color LCDs */
  233.                     HasDepth ( gdh , 16 , 1 , 1 ) ||
  234.                     HasDepth ( gdh , 4 , 1 , 1 ) || /* why here!? */
  235.                     HasDepth ( gdh , 32 , 1 , 1 ) ) {
  236.  
  237.                     _mt_in_color = 1 ;
  238.                     break ;
  239.                 }
  240.             }
  241.             gdh = GetNextDevice ( gdh ) ;
  242.         }
  243.     }
  244.  
  245.     mustwork ( create_tty ( & _mt_window , MT_WINDOW , _mt_in_color ) ) ;
  246.     ( ( WindowPeek ) _mt_window ) -> windowKind = ( WIN_BASE_KIND + NHW_MAP ) ;
  247.     SelectWindow ( _mt_window ) ;
  248.     SetPort ( _mt_window ) ;
  249.     SetOrigin ( -3 , -3 ) ;
  250.     font_num = 0 ;
  251.     font_size = ( flags.large_font && ! small_screen ) ? 12 : 9 ;
  252.     GetFNum ( "\PHackFont" , & font_num ) ;
  253.     if ( font_num != 0 ) {
  254.         mustwork ( init_tty_number ( _mt_window , font_num , font_size ,
  255.             MT_WIDTH , MT_HEIGHT + 1 ) ) ;
  256.     } else {
  257.         mustwork ( init_tty_name ( _mt_window , "\PMonaco" , font_size ,
  258.             MT_WIDTH , MT_HEIGHT + 1 ) ) ;
  259.     }
  260.  
  261.     mustwork ( get_tty_metrics ( _mt_window , & num_cols , & num_rows , & win_width ,
  262.         & win_height , & font_num , & font_size , & char_width , & row_height ) ) ;
  263.  
  264.     SizeWindow ( _mt_window , win_width + 6 , win_height + 6 , 1 ) ;
  265.     dprintf ( "Checking for TTY window position" ) ;
  266.     if ( RetrievePosition ( kMapWindow , & vert , & hor ) ) {
  267.         dprintf ( "Moving window to (%d,%d)" , hor , vert ) ;
  268.         MoveWindow ( _mt_window , hor , vert , 1 ) ;
  269.     }
  270.     ShowWindow ( _mt_window ) ;
  271.     SetPort ( _mt_window ) ;
  272.  
  273.     mustwork ( get_tty_attrib ( _mt_window , TTY_ATTRIB_FLAGS , & flag ) ) ;
  274.     
  275.     /* Start in raw, always flushing mode */
  276.  
  277.     flag |= TA_ALWAYS_REFRESH | TA_WRAP_AROUND;
  278.     mustwork ( set_tty_attrib ( _mt_window , TTY_ATTRIB_FLAGS , flag ) ) ;
  279.  
  280.     mustwork ( get_tty_attrib ( _mt_window , TTY_ATTRIB_CURSOR , & flag ) ) ;
  281.     
  282.     flag |= TA_BLINKING_CURSOR;
  283.  
  284. #ifdef applec
  285.     flag &= ~ TA_CR_ADD_NL ;
  286. #else
  287.     flag &= ~ TA_NL_ADD_CR ;
  288. #endif
  289.  
  290.     mustwork ( set_tty_attrib ( _mt_window , TTY_ATTRIB_CURSOR , flag ) ) ;
  291.  
  292.     InitRes ( ) ;
  293. }
  294.  
  295.  
  296. static void
  297. _mt_handle_event ( EventRecord * event ) {
  298. Rect r ;
  299. int code ;
  300. WindowPtr window ;
  301.  
  302.     if ( event -> what == mouseDown ) {
  303.         r = ( * GetGrayRgn ( ) ) -> rgnBBox ;
  304.         InsetRect ( & r , 3 , 3 ) ;
  305.  
  306.         code = FindWindow ( event -> where , & window ) ;
  307.         switch ( code ) {
  308.             case inDrag :
  309.                 DragWindow ( window , event -> where , & r ) ;
  310.                 if ( window == _mt_window ) {
  311.                     SaveWindowPos ( window ) ;
  312.                 }
  313.                 break ;
  314.             case inSysWindow :
  315.                 SystemClick ( event , window ) ;
  316.                 break ;
  317.             case inMenuBar :
  318.                 UpdateMenus ( ) ;
  319.                 DoMenu ( MenuSelect ( event -> where ) ) ;
  320.                 break ;
  321.             default :
  322.                 /* Do nothing */
  323.                 ;
  324.         }
  325.     } else if ( event -> what == diskEvt ) {
  326.         if ( event -> message & 0xffff0000 != 0L ) {
  327.         Point p = { 100 , 100 } ;
  328.  
  329.             ( void ) itworked ( DIBadMount ( p , event -> message ) ) ;
  330.         }
  331.     }
  332. }
  333.  
  334.  
  335. int
  336. tgetch ( void ) {
  337. EventRecord event ;
  338. long sleepTime = 0 ;
  339. int ret ;
  340. int key ;
  341.  
  342.     while ( 1 ) {
  343.         update_tty ( _mt_window ) ;
  344.         ret = GetFromKeyQueue ( ) ;
  345.         if ( ret ) {
  346.             return ret ;
  347.         }
  348.         WaitNextEvent ( -1 , & event , sleepTime , 0 ) ;
  349.         SetPort ( _mt_window ) ;
  350.         if ( handle_tty_event ( _mt_window , & event ) ) {
  351.             _mt_handle_event ( & event ) ;
  352.         }
  353.         if ( event . what == keyDown || event . what == autoKey ) {
  354.             if ( ! ( event . modifiers & cmdKey ) ) {
  355.                 key = event . message & 0xff;
  356.                 if(key == '\r') key = '\n';
  357.                 return ( key ) ;
  358.             } else {
  359.                 DoMenu ( MenuKey ( event . message & 0xff ) ) ;
  360.             }
  361.         } else if ( ! sleepTime ) {
  362.             Point p = event . where ;
  363.             GlobalToLocal ( & p ) ;
  364.             if ( PtInRect ( p , & ( _mt_window -> portRect ) ) ) {
  365.                 ObscureCursor ( ) ;
  366.             } else {
  367.                 InitCursor ( ) ;
  368.             }
  369.         }
  370.         if ( event . what == nullEvent ) {
  371.             sleepTime = GetCaretTime ( ) ;
  372.         } else {
  373.             sleepTime = 0 ;
  374.         }
  375.     }
  376. }
  377.  
  378.  
  379. void
  380. getreturn ( char * str ) {
  381.     FlushEvents ( -1 , 0 ) ;
  382.     printf_tty ( _mt_window , "Press space %s" , str ) ;
  383.     ( void ) tgetch ( ) ;
  384. }
  385.  
  386.  
  387. int
  388. has_color ( int color ) {
  389. #if defined(applec)
  390. # pragma unused(color)
  391. #endif
  392. Rect r;
  393. Point p = { 0 , 0 } ;
  394. GDHandle gh ;
  395.  
  396.     if ( ! _mt_in_color ) {
  397.         return 0 ;
  398.     }
  399.  
  400.     r = _mt_window -> portRect ;
  401.     SetPort ( _mt_window ) ;
  402.     GlobalToLocal ( & p ) ;
  403.     OffsetRect ( & r , p . h , p . v ) ;
  404.  
  405.     gh = GetMaxDevice ( & r ) ;
  406.     if ( ! gh ) {
  407.         return 0 ;
  408.     }
  409.  
  410.     return ( * ( ( * gh ) -> gdPMap ) ) -> pixelSize > 4 ; /* > 4 bpp */
  411. }
  412.  
  413.  
  414. void
  415. tty_delay_output ( void ) {
  416. EventRecord event ;
  417. long toWhen = TickCount ( ) + 3 ;
  418.  
  419.     while ( TickCount ( ) < toWhen ) {
  420.         WaitNextEvent ( updateMask , & event , 3L , 0 ) ;
  421.         if ( event . what == updateEvt ) {
  422.             if ( ! handle_tty_event ( _mt_window , & event ) ) {
  423.                 _mt_handle_event ( & event ) ;
  424.             }
  425.         }
  426.     }
  427. }
  428.  
  429.  
  430. void
  431. tty_nhbell ( void ) {
  432.     SysBeep ( 20 ) ;
  433. }
  434.  
  435.  
  436. void
  437. cmov ( int x , int y ) {
  438.     move_tty_cursor ( _mt_window , x , y ) ;
  439.     ttyDisplay -> cury = y ;
  440.     ttyDisplay -> curx = x ;
  441. }
  442.  
  443.  
  444. void
  445. nocmov ( int x , int y ) {
  446.     cmov ( x , y ) ;
  447. }
  448.  
  449.  
  450. static void
  451. _mt_set_colors ( long * colors ) {
  452. short err ;
  453.  
  454.     if ( ! _mt_in_color ) {
  455.         return ;
  456.     }
  457.     err = set_tty_attrib ( _mt_window , TTY_ATTRIB_FOREGROUND , colors [ 0 ] ) ;
  458.     err = set_tty_attrib ( _mt_window , TTY_ATTRIB_BACKGROUND , colors [ 1 ] ) ;
  459. }
  460.  
  461.  
  462. void
  463. term_end_attr ( int attr ) {
  464. #if defined(applec)
  465. # pragma unused ( attr )
  466. #endif
  467.     _mt_set_colors ( _mt_attrs [ 0 ] ) ;
  468. }
  469.  
  470.  
  471. void
  472. term_start_attr ( int attr ) {
  473.     switch ( attr ) {
  474.         case ATR_ULINE:
  475.             _mt_set_colors ( _mt_attrs [ 1 ] ) ;
  476.             break ;
  477.         case ATR_BOLD:
  478.             _mt_set_colors ( _mt_attrs [ 2 ] ) ;
  479.             break ;
  480.         case ATR_BLINK:
  481.             _mt_set_colors ( _mt_attrs [ 3 ] ) ;
  482.             break ;
  483.         case ATR_INVERSE:
  484.             _mt_set_colors ( _mt_attrs [ 4 ] ) ;
  485.             break ;
  486.         default:
  487.             _mt_set_colors ( _mt_attrs [ 0 ] ) ;
  488.             break ;
  489.     }
  490. }
  491.  
  492.  
  493. void
  494. standoutend ( void ) {
  495.     term_end_attr ( ATR_INVERSE ) ;
  496. }
  497.  
  498.  
  499. void
  500. standoutbeg ( void ) {
  501.     term_start_attr ( ATR_INVERSE ) ;
  502. }
  503.  
  504.  
  505. void
  506. xputs ( const char * str ) {
  507. short err ;
  508.  
  509.     err = add_tty_string ( _mt_window , str ) ;
  510. }
  511.  
  512.  
  513. void
  514. term_end_color ( void ) {
  515.     _mt_set_colors ( _mt_colors [ NO_COLOR ] ) ;
  516. }
  517.  
  518.  
  519. void
  520. cl_end ( void ) {
  521. short err ;
  522.  
  523.     _mt_set_colors ( _mt_attrs [ 0 ] ) ;
  524.     err = clear_tty_window ( _mt_window , ttyDisplay -> curx , ttyDisplay -> cury ,
  525.         MT_WIDTH - 1 , ttyDisplay -> cury ) ;
  526. }
  527.  
  528.  
  529. void
  530. clear_screen ( void ) {
  531. short err ;
  532.  
  533.     _mt_set_colors ( _mt_attrs [ 0 ] ) ;
  534.     err = clear_tty ( _mt_window ) ;
  535. }
  536.  
  537.  
  538. void
  539. cl_eos ( void ) {
  540. short err ;
  541.  
  542.     cl_end ( ) ;
  543.     _mt_set_colors ( _mt_attrs [ 0 ] ) ;
  544.     err = clear_tty_window ( _mt_window , 0 , ttyDisplay -> cury + 1 , MT_WIDTH - 1 ,
  545.         MT_HEIGHT - 1 ) ;
  546. }
  547.  
  548.  
  549. void
  550. home ( void ) {
  551. short err ;
  552.  
  553.     err = move_tty_cursor ( _mt_window , 0 , 0 ) ;
  554.     ttyDisplay -> curx = 0 ;
  555.     ttyDisplay -> cury = 0 ;
  556. }
  557.  
  558.  
  559. void
  560. backsp ( void ) {
  561. short err ;
  562.  
  563.     err = add_tty_char ( _mt_window , 8 ) ;
  564.     err = add_tty_char ( _mt_window , 32 ) ;
  565.     err = add_tty_char ( _mt_window , 8 ) ;
  566.     err = update_tty ( _mt_window ) ;
  567. }
  568.  
  569.  
  570. void
  571. msmsg ( const char * str , ... ) {
  572. va_list args ;
  573. char * buf = (char *) alloc ( 1000 ) ;
  574.  
  575.     va_start ( args , str ) ;
  576.     vsprintf ( buf , str , args ) ;
  577.     va_end ( args ) ;
  578.  
  579.     xputs ( buf ) ;
  580.     free ( buf ) ;
  581. }
  582.  
  583.  
  584. void
  585. term_end_raw_bold ( void ) {
  586.     standoutend ( ) ;
  587. }
  588.  
  589.  
  590. void
  591. term_start_raw_bold ( void ) {
  592.     standoutbeg ( ) ;
  593. }
  594.  
  595.  
  596. void
  597. term_start_color ( int color ) {
  598.     if ( color >= 0 && color < MAXCOLORS ) {
  599.         _mt_set_colors ( _mt_colors [ color ] ) ;
  600.     }
  601. }
  602.  
  603.  
  604. void
  605. setftty ( void ) {
  606. long flag ;
  607.  
  608.     mustwork ( get_tty_attrib ( _mt_window , TTY_ATTRIB_FLAGS , & flag ) ) ;
  609. /* Buffered output in the game */
  610.     flag &= ~ TA_ALWAYS_REFRESH ;
  611.     flag |= TA_INHIBIT_VERT_SCROLL ; /* don't scroll */
  612.     mustwork ( set_tty_attrib ( _mt_window , TTY_ATTRIB_FLAGS , flag ) ) ;
  613.  
  614.     mustwork ( get_tty_attrib ( _mt_window , TTY_ATTRIB_CURSOR , & flag ) ) ;
  615.  
  616. #ifdef applec
  617.     flag &= ~ TA_CR_ADD_NL ;
  618. #else
  619.     flag &= ~ TA_NL_ADD_CR ;
  620. #endif
  621.  
  622.     mustwork ( set_tty_attrib ( _mt_window , TTY_ATTRIB_CURSOR , flag ) ) ;
  623.  
  624.     flags . cbreak = 1 ;
  625. }
  626.  
  627.  
  628. void
  629. tty_startup ( int * width , int * height  ) {
  630.     _mt_init_stuff ( ) ;
  631.     * width = MT_WIDTH ;
  632.     * height = MT_HEIGHT ;
  633. }
  634.  
  635.  
  636. void
  637. gettty ( void ) {
  638. }
  639.  
  640.  
  641. void
  642. settty ( char * str ) {
  643. long flag ;
  644.  
  645.     update_tty ( _mt_window ) ;
  646.  
  647.     mustwork ( get_tty_attrib ( _mt_window , TTY_ATTRIB_FLAGS , & flag ) ) ;
  648. /* Buffered output in the game, raw in "raw" mode */
  649.     flag &= ~ TA_INHIBIT_VERT_SCROLL ; /* scroll */
  650.     flag |= TA_ALWAYS_REFRESH ;
  651.     mustwork ( set_tty_attrib ( _mt_window , TTY_ATTRIB_FLAGS , flag ) ) ;
  652.  
  653.     mustwork ( get_tty_attrib ( _mt_window , TTY_ATTRIB_CURSOR , & flag ) ) ;
  654.  
  655. #ifdef applec
  656.     flag |= TA_CR_ADD_NL ;
  657. #else
  658.     flag |= TA_NL_ADD_CR ;
  659. #endif
  660.  
  661.     mustwork ( set_tty_attrib ( _mt_window , TTY_ATTRIB_CURSOR , flag ) ) ;
  662.  
  663.     tty_raw_print ( "\n" ) ;
  664.     if ( str ) {
  665.         tty_raw_print ( str ) ;
  666.     }
  667. }
  668.  
  669.  
  670. void
  671. tty_number_pad ( int arg ) {
  672. #if defined(applec)
  673. # pragma unused(arg)
  674. #endif
  675. }
  676.  
  677.  
  678. void
  679. tty_start_screen ( void ) {
  680.     flags . cbreak = 1 ;
  681. }
  682.  
  683.  
  684. void
  685. tty_end_screen ( void ) {
  686. }
  687.  
  688.  
  689. int
  690. term_puts ( char * str ) {
  691.     xputs ( str ) ;
  692.     return strlen ( str ) ;
  693. }
  694.  
  695.  
  696. int
  697. term_putc ( int c ) {
  698. short err ;
  699.  
  700.     err = add_tty_char ( _mt_window , c ) ;
  701.     return err ? EOF : c ;
  702. }
  703.  
  704.  
  705. int
  706. term_flush ( void * desc ) {
  707.     if ( desc == stdout || desc == stderr ) {
  708.         update_tty ( _mt_window ) ;
  709.     } else {
  710.         impossible ( "Substituted flush for file" ) ;
  711.         return fflush ( desc ) ;
  712.     }
  713.     return 0 ;
  714. }
  715.